﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SchEdu.Framework.DataModel;
using SchEdu.Framework.Validators;

namespace SchEdu.Framework.Objective
{
    class AverageWeighedEarliness : Objective
    {
        public AverageWeighedEarliness()
            : base()
        {
        }
        public AverageWeighedEarliness(SchEduData schEduData, SchEduDataSet.SolutionRow solution)
            : base(schEduData, solution)
        {
        }
        protected override void Logic()
        {
            double averageWeighedEarliness = 0;
            double totalWeighedEarliness = 0;

            int earliness = 0;

            foreach (SchEduDataSet.OrderRow order in SchEduData.Order)
            {
                earliness = order.DueDate - order.EndDate;
                totalWeighedEarliness = totalWeighedEarliness + (order.Weight * earliness);
            }

            averageWeighedEarliness = totalWeighedEarliness / SchEduData.Order.Count;

            GeneratePerformanceRow();

            performance.Value = Math.Round(averageWeighedEarliness,2);


        }

        protected override void InitializeValidators()
        {
            base.InitializeValidators();
            validators.Add(new OrderWeightValidator(SchEduData));
            validators.Add(new OrderEndDateValidator(SchEduData));
            validators.Add(new OrderDueDateValidator(SchEduData));
        }

        public override AboutInfo AboutInfo
        {
            get
            {
                AboutInfo aboutInfo = new AboutInfo();
                aboutInfo.Title = "Average Weighed Earliness";
                aboutInfo.Guid = new Guid("{DF0C5190-19F3-4492-B866-7394A4882F65}");
                aboutInfo.Description = Resources.AverageWeighedEarlinessDescription;
                return aboutInfo;
            }
        }

    }
}
